package Test11_16;

import java.io.*;

public class Test03 {
    public static void main(String[] args) {
        //2：附件 chaoxian.txt是个文本文件，用程序把其中的金正恩替换成 金三胖，
        // 提示：把内容取出来，替换后，写入文件。
        FileWriter fw = null;
        BufferedReader bw = null;
        try {
            fw = new FileWriter("D:\\aaa\\chapter03.txt");
            bw = new BufferedReader(new FileReader("D:\\aaa\\chapter02.txt"));
            String reader;
            while ((reader=bw.readLine())!=null){
                reader = reader.replace("金正恩","金三胖");
                fw.write(reader);
                System.out.println(reader);
                fw.write("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }  catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fw.close();
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
